package com.explorati.interview.interview.chaptersix;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerialTest {

	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		Student stu = new Student();
		stu.setAge(20);
		stu.setName("zhangsan");
		//创建一个对象输入流
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("e:/test/a.txt"));
		oos.writeObject(stu);
		oos.close();

		//创建一个对象输入流
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream("e:/test/a.txt"));
		Object obj = ois.readObject();
		Student stuBak = (Student) obj;
		//打印在控制台，查看序列化和反序列化是否成功
		System.out.println("stu name is : " + stuBak.getName());
		System.out.println("stu age is : " + stuBak.getAge());
	}
}
/**
 * 运行结果：
stu name is : zhangsan
stu age is : 20
*/
